package com.jctrip.hotel.source.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.google.common.collect.Maps;
import com.jctrip.hotel.common.util.JsonUtil;
import com.jctrip.hotel.source.model.Result;
import com.jctrip.hotel.source.model.meituan.req.*;
import com.jctrip.hotel.source.service.meituan.MeituanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Author: zxy
 * @CreateTime: 2023-12-26 14:36
 * @Description:
 */
@Slf4j
@Api(tags = "meituan")
@RestController
@RequestMapping("/meituan")
@ApiSupport(order = 8)
public class MeituanController {
    @Autowired
    private MeituanService meituanService;


    @PostMapping("/poiList")
    @ApiOperation("查询酒店id列表")
    @ApiOperationSupport(order = 1)
    public Result poiListMeituan(@RequestBody PoiListReq req,
                                 @RequestParam Integer partnerId,
                                 @RequestParam String accesskey,
                                 @RequestParam String secretKey) {
        try {
            return Result.ok(meituanService.poiListMeituan(req, partnerId, accesskey, secretKey));
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }

    @PostMapping("/goodsRp")
    @ApiOperation("查询酒店下产品列表")
    @ApiOperationSupport(order = 2)
    public Result goodsRpMeituan(@RequestBody GoodsRpReq req,
                                 @RequestParam Integer partnerId,
                                 @RequestParam String accesskey,
                                 @RequestParam String secretKey) {
        try {
            return Result.ok(meituanService.goodsRpMeituan(req, partnerId, accesskey, secretKey));
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }

    @PostMapping("/content")
    @ApiOperation("查询酒店详情V2")
    @ApiOperationSupport(order = 3)
    public Result contentMeituan(@RequestBody ContentReq req,
                                 @RequestParam Integer partnerId,
                                 @RequestParam String accesskey,
                                 @RequestParam String secretKey) {
        try {
            return Result.ok(meituanService.contentMeituan(req, partnerId, accesskey, secretKey));
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }

    @PostMapping("/realroomContent")
    @ApiOperation("查询物理房型V2")
    @ApiOperationSupport(order = 4)
    public Result realroomContentMeituan(@RequestBody RealroomContentReq req,
                                         @RequestParam Integer partnerId,
                                         @RequestParam String accesskey,
                                         @RequestParam String secretKey) {
        try {
            return Result.ok(meituanService.realroomContentMeituan(req, partnerId, accesskey, secretKey));
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }

    @PostMapping("/orderCheck")
    @ApiOperation("下单前校验")
    @ApiOperationSupport(order = 5)
    public Result orderCheckMeituan(@RequestBody OrderCheckReq req,
                                    @RequestParam Integer partnerId,
                                    @RequestParam String accesskey,
                                    @RequestParam String secretKey) {
        try {
            return Result.ok(meituanService.orderCheckMeituan(req, partnerId, accesskey, secretKey));
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }

    @PostMapping("/orderBooking")
    @ApiOperation("预约下单")
    @ApiOperationSupport(order = 6)
    public Result orderBookingMeituan(@RequestBody OrderBookingReq req,
                                      @RequestParam Integer partnerId,
                                      @RequestParam String accesskey,
                                      @RequestParam String secretKey) {
        try {
            return Result.ok(meituanService.orderBookingMeituan(req, partnerId, accesskey, secretKey));
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }

    @PostMapping("/orderCancel")
    @ApiOperation("取消订单")
    @ApiOperationSupport(order = 7)
    public Result orderCancelMeituan(@RequestBody OrderCancelReq req,
                                     @RequestParam Integer partnerId,
                                     @RequestParam String accesskey,
                                     @RequestParam String secretKey) {
        try {
            return Result.ok(meituanService.orderCancelMeituan(req, partnerId, accesskey, secretKey));
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }

    @PostMapping("/orderQuery")
    @ApiOperation("查询订单")
    @ApiOperationSupport(order = 8)
    public Result orderQueryMeituan(@RequestBody OrderQueryReq req,
                                    @RequestParam Integer partnerId,
                                    @RequestParam String accesskey,
                                    @RequestParam String secretKey) {
        try {
            return Result.ok(meituanService.orderQueryMeituan(req, partnerId, accesskey, secretKey));
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }

    @PostMapping("/orderReminder")
    @ApiOperation("酒店催单")
    @ApiOperationSupport(order = 9)
    public Result orderReminderMeituan(@RequestBody OrderReminderReq req,
                                       @RequestParam Integer partnerId,
                                       @RequestParam String accesskey,
                                       @RequestParam String secretKey) {
        try {
            return Result.ok(meituanService.orderReminderMeituan(req, partnerId, accesskey, secretKey));
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }

    @PostMapping("/orderCallback")
    @ApiOperation("订单状态变更")
    @ApiOperationSupport(order = 10)
    public Map orderCallbackMeituan(@RequestBody MeituanReq req) {
        Map<String, Object> maps = Maps.newHashMap();
        maps.put("code", 0);
        maps.put("message", "成功");
        try {
            meituanService.orderCallback(req);
        } catch (Exception e) {
            log.error(e.getMessage());
        }
        return maps;
    }

    @PostMapping("/poiCallback")
    @ApiOperation("酒店变更")
    @ApiOperationSupport(order = 11)
    public Map poiCallbackMeituan(@RequestBody MeituanReq req) {
        Map<String, Object> maps = Maps.newHashMap();
        maps.put("code", 0);
        maps.put("message", "成功");
        try {
            log.info("poi-callback = {}", JsonUtil.toString(req));
            meituanService.poiCallback(req);
        } catch (Exception e) {
            log.error(e.getMessage());
        }
        return maps;
    }

    @PostMapping("/goodCallback")
    @ApiOperation("产品变更")
    @ApiOperationSupport(order = 12)
    public Map goodCallbackMeituan(@RequestBody MeituanReq req) {
        Map<String, Object> maps = Maps.newHashMap();
        maps.put("code", 0);
        maps.put("message", "成功");
        try {
            log.info("good-callback = {}", JsonUtil.toString(req));
            meituanService.goodCallback(req);
        } catch (Exception e) {
            log.error(e.getMessage());
        }
        return maps;
    }
}
